home *** CD-ROM | disk | FTP | other *** search
-
-
-
- GETOPT User Commands GETOPT
-
-
-
- NNAAMMEE
- getopt - format flags for shell scripts
-
- SSYYNNOOPPSSIISS
- ggeettoopptt flag_spec argument ...
-
- DDEESSCCRRIIPPTTIIOONN
- _G_e_t_o_p_t is a program intended to be called by scripts to
- ``canonicalize'' their arguments before processing them,
- just as the _g_e_t_o_p_t(3) routine does for C programs. (This
- need for scripts is usually most noticeable in the way
- _l_i_n_t(1) handles the --nn flag.)
-
- The following two examples provide the initial parsing for a
- script which takes two flags, --aa and --bb, the second of which
- takes an argument.
- # For /bin/csh...
- set argv = (`getopt "ab:" $*`)
- if ( $status ) then
- echo "Read the documentation and try again." >/dev/tty
- exit 1
- endif
- set Aflag=0
- set Name=NONE
- while "$1" != "--"
- switch ("$1")
- case '-a':
- set Aflag=1
- breaksw
- case '-b':
- shift
- set Name=$1
- breaksw
- endsw
- shift
- end
- shift
- echo Aflag=$Aflag / Name=$Name / Remaining args are $*
-
- # For /bin/sh...
- set -- `getopt "d:s" $@`
- if test $? != 0 ; then
- echo "Read the documentation and try again."
- exit 1
- fi
- Aflag=0
- Name=NONE
- for f
- do
- case "$f" in
- -a) Aflag=1
- ;;
-
-
-
- Sprite v1.0 LOCAL 1
-
-
-
-
-
-
- GETOPT User Commands GETOPT
-
-
-
- -b) shift
- Name=$2
- ;;
- --) break
- ;;
- esac
- shift
- done
- shift
- echo Aflag=$Aflag / Name=$Name / Remaining args are $*
-
- DDIIAAGGNNOOSSTTIICCSS
- The program burps the standard _g_e_t_o_p_t(3) diagnostics to
- standard error, and exits with a non-zero status if an error
- occurs. It is arguable wrong that the diagnostics imply
- that the program is named ``getopt'' rather than the real
- name of the script. It is undeniably AT&T-compatible to do
- this, however.
-
- SSEEEE AALLSSOO
- csh(1), sh(1), getopt(3)
-
- AAUUTTHHOORR
- Rich $alz
- Mirror Systems
- (mirror!rs, rs@mirror.TMC.COM)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Sprite v1.0 LOCAL 2
-
-
-
-